package com.lagou;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 输入的kv: key为文本每行的偏移量，value为一行的文本
 * 输出的kv: key为文本每行的数字，value为null
 * @author lxh
 * @date 2021/3/2
 */
public class SortNumberMapper extends Mapper<LongWritable, Text, LongWritable, NullWritable> {
    LongWritable writable = new LongWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //将一行文本转为字符串
        String line = value.toString();
        //将文本内容转为整型并封装为LongWritable
        writable.set(Long.parseLong(line));
        context.write(writable,NullWritable.get());
    }
}
